<?php
include ('../../__global.php');

class aj_scrollSgd extends ml_controller {
    
    private $searchKey;
    private $searchSort;
    private $block;
    private $aid;
    
    function initParam(){
        
        $this->searchKey = $this->input('searchKey', '', '');
        $this->searchSort = $this->input('sort','','hot');
        $page = intval($this->input('page' , '' , 1));
        $segment = $this->input('segment', '', 1);
        
        $segment = $segment==1? 1: 2;
        $page = 1>$page? 1: $page;
        
        $this->block = ($page-1)*3+ $segment;
        $this->aid = $this->__visitor['uid'];
    }
    
    function checkParam(){
        
        //$this->searchKey = Tool_antiXss::clean_danger_param(trim($this->searchKey));
        
    }
    
    function main(){

        //行为LOG
        $ext = array(
            'block' => $this->block,
            'order' => $this->searchSort,
        );
        ml_tool_actionlog::view_search($this->__visitor['uid'] , 'gd' , $this->searchKey , $ext);
        
        $oSearch = new ml_biz_search_gd($this->searchKey, $this->aid, $this->block);
        $oSearch->setSearchSort($this->searchSort);
        $aHtml = $oSearch->getSearchResult();
        
        $total_block = $oSearch->get_total_block();

        $data['items'] = $aHtml;
        $data['lastSegment'] = $this->block == $total_block-1 ? true : false;    
        
        $this->api_output(ML_RCODE_SUCC, $data);
    }
    
}

new aj_scrollSgd();
